package com.kaifamiao.N0803;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class Node4 {

    public static void main(String[] args) throws UnsupportedEncodingException {

        // 当前默认编码 UTF-8
        System.out.println(Charset.defaultCharset());

        // 以 默认编码(UTF-8)将字符串转换为 byte 数组
        // "utf8" "utf-8"   Charset.forName("utf-8")
        byte[] bytes = "智者谋其利，愚者争虚名".getBytes("GBK");

        System.out.println(Arrays.toString(bytes));
        System.out.println(bytes.length);
        byte[] bytes1 = Arrays.copyOf(bytes, 50);

        String str = new String(bytes1, 0, 22, "GBk");

        System.out.println(str);
        // 乱码， 编码和解码使用的字符集不同造成的


        char[] chs = {'世', '界', '上', '只', '有', '一', '个', '中', '国'};

        String s = new String(chs);
        System.out.println(s);

    }
}